<?php include "connection.php";?>
<?php include "checkSession.php";?>




<?



$start_year  = $_REQUEST['start_year'];
$start_month = $_REQUEST['start_month'];
$start_day   = $_REQUEST['start_days'];


if(!$_REQUEST['start_year'])
{$start_year=date("Y",time());}

if(!$_REQUEST['start_month'])
{$start_month=date("m",time());}

if(!$_REQUEST['start_days'])
{$start_day=date("d",time());}


$date_time=$start_year."年".$start_month."月".$start_day."日";
//echo $end_year  = $_REQUEST['end_year'];
//echo $end_month = $_REQUEST['end_month'];
//echo $end_day   = $_REQUEST['end_days'];
?>







<?

$table = "feedback";
$query = mysql_query("SELECT COUNT(nid) FROM $table where datetime = '$date_time'");
$sum = mysql_result($query, 0);

?>







<?php

$nowpageid = 1;
$detailnum = 20; //每页显示多少个产品


if ($_REQUEST ['nowpageid']) {
    $nowpageid = $_REQUEST ['nowpageid'];
} else {
    $nowpageid = 1;
}


//计算一下结果，从那条数据开始显示
$detailstar = ($nowpageid - 1) * $detailnum;


if ($sum) {

    if ($sum < $detailnum) {
        $page_count = 1;
        $detailnum = $sum;
    } //如果总数据量小于$Pagenum,（pagenum作为每页显示数据的条数，）那么只有一页,而pagenum也更改为sum?


    else if ($sum % $detailnum) {
        $page_count = (int)($sum / $detailnum) + 1;
    }
    //取总数据量除以每页数的余数?
    //如果有余数，则页数等于总数据量除以每页数的结果取整再加一


    else {
        $page_count = $sum / $detailnum;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果?

} else {
    $page_count = 0;
    $detailnum = 0;
}


$lastpage = $page_count;
$prepage = $nowpageid - 1;
$nextpage = $nowpageid + 1;


if ($nowpageid == 1) {
    $prepage = 1;
}


if ($nowpageid == $page_count) {

    if ($sum <= $detailnum) //总数数据少于每页显示数目，就把循环改成总数数目
    {
        $detailnum = $sum;
        $nextpage = $nowpageid;
    } else {
        $nextpage = $nowpageid;
        $detailnum = fmod($sum, $detailnum);
        if ($detailnum == 0) //这个if是因为当数据正好30条，能除尽的话，最后一页就会因为fmod能整除的缘故，最后一页不显示数据
        {
            $detailnum = 5;
        }
    }
    //如果现在页数等于总页数（总页数上面求出，最后一页不够循环数的时候），那么最后一页的detailnum就会等于余下数据(不足一页)的数目.

}

?>









<!--开始搜索对应的detail资料-->

<?

$table = "feedback";
//设置需要搜索的表格的前缀后缀


//设置需要搜索的表格的排序项和升降项
$sort_by = "nid";
$sort_order = "desc";
//设置需要搜索的表格的排序项和升降项


if ($_REQUEST ['sortby']) {
    $sort_by = $_REQUEST ['sortby'];
}


if ($_REQUEST ['sortorder']) {
    $sort_order = $_REQUEST ['sortorder'];
}



$result = mysql_query("select * from $table where datetime = '$date_time' ORDER BY $sort_by $sort_order  limit $detailstar ,
$detailnum");


while ($row = mysql_fetch_array($result)) {

    $nid[] = $row['nid'];

    $q1[] = $row['q1'];
    $q2[]  = $row['q2'];
    $q3[]  = $row['q3'];
    $q4[]  = $row['q4'];
    $q5[]  = $row['q5'];
    $q6[]  = $row['q6'];
    $q7[]  = $row['q7'];
    $q8[]  = $row['q8'];
    $q9[]  = $row['q9'];
    $q10[]  = $row['q10'];

    $remark[]     = $row['remark'];
    $best_meal[]  = $row['best_meal'];
    $worst_meal[] = $row['worst_meal'];
    $datetime[]   = $row['datetime'];
    $user2_id[]    = $row['user_id'];
    $mealat[]     = $row['mealat'];
    $user2_name[]  = $row['user_name'];


}



$full_result = mysql_query("select * from $table where datetime = '$date_time' ");




while ($row = mysql_fetch_array($full_result)) {

    $full_nid[] = $row['nid'];

    $full_q1[] = $row['q1'];
    $full_q2[]  = $row['q2'];
    $full_q3[]  = $row['q3'];
    $full_q4[]  = $row['q4'];
    $full_q5[]  = $row['q5'];
    $full_q6[]  = $row['q6'];
    $full_q7[]  = $row['q7'];
    $full_q8[]  = $row['q8'];
    $full_q9[]  = $row['q9'];
    $full_q10[]  = $row['q10'];

    $full_remark[]     = $row['remark'];
    $full_best_meal[]  = $row['best_meal'];
    $full_worst_meal[] = $row['worst_meal'];
    $full_datetime[]   = $row['datetime'];


}



$full_q1_new=array_count_values($full_q1);
$full_q2_new=array_count_values($full_q2);
$full_q3_new=array_count_values($full_q3);
$full_q4_new=array_count_values($full_q4);
$full_q5_new=array_count_values($full_q5);
$full_q6_new=array_count_values($full_q6);
$full_q7_new=array_count_values($full_q7);
$full_q8_new=array_count_values($full_q8);
$full_q9_new=array_count_values($full_q9);
$full_q10_new=array_count_values($full_q10);




mysql_close($con);

?>





